﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HRC.Library.ContextFoundation;
using Lehnet.BusinessLayer;
using Lehnet.BusinessLayer.Interfaces;
using Lehnet.Models;

namespace Lehnet.WebUI.Controllers
{
    public class MusteriPersoneliController : Controller
    {
        //
        // GET: /MusteriPersoneli/

        public PartialViewResult Index(int Id)
        {
            var mpb = ProxyHelper<MusteriPersonelBusiness, IMusteriPersonelBusiness>.Instance.AddOrGet();
            List<Models.MusteriPersonel> musteriPersonelList = mpb.LoadAllMusteriPersonelByMusteriId(Id);
            ViewBag.MusteriId = Id;
            return PartialView(musteriPersonelList);

        }
        public PartialViewResult Create(int musteriId, int? id)
        {
            var mp = new MusteriPersonel();
            mp.MusteriId = musteriId;
            if (id != null)
            {
                var mpb = ProxyHelper<MusteriPersonelBusiness, IMusteriPersonelBusiness>.Instance.AddOrGet();
                mp = mpb.LoadMusteriPersonelById(id.Value);
            }
            return PartialView(mp);
        }

        [HttpPost]
        public PartialViewResult Create(Models.MusteriPersonel musteriPersonel)
        {
            var mpb = ProxyHelper<MusteriPersonelBusiness, IMusteriPersonelBusiness>.Instance.AddOrGet();
            mpb.SaveOrUpdate(musteriPersonel);
            ViewBag.Message = "Yeni müşteri personeli kaydı başarılı bir şekilde yapılmıştır.";
            return PartialView(musteriPersonel);
        }

        public JsonResult DeleteMusteriPersoneliAjax(int musteriPersonelId)
        {
            var mpb = ProxyHelper<MusteriPersonelBusiness, IMusteriPersonelBusiness>.Instance.AddOrGet();
            mpb.Delete(musteriPersonelId);
            JsonResult result = Json("Oldu, çok da güzel oldu!");
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }

    }
}
